package filter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import pojo.Author;
import pojo.Thongso;
import pojo.Topic;

import dao.AuthorDAO;
import dao.ThongsoDAO;
import dao.TopicDAO;


/**
 * Servlet Filter implementation class MainFilter
 */
public class MainFilter implements Filter {

    /**
     * Default constructor. 
     */
    public MainFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		HttpServletRequest req = (HttpServletRequest)request; 
		TopicDAO tt= new TopicDAO();
		List<Topic> lmenu1=tt.getMenuCap1();
    	AuthorDAO ad= new AuthorDAO();
    	List<Author> la=ad.getTopAuthor(10);
    	ThongsoDAO td= new ThongsoDAO();
    	Thongso ts=td.getThongsoByID(1);
    	req.setAttribute("soBookMacDinh",ts.getSoBookMacDinh());
    	req.setAttribute("soBookTrenTrang", ts.getSoBookTrenTrang());
    	req.setAttribute("kieuSapXep", ts.getKieuSapXep());
    	req.setAttribute("lAuthor", la);
		req.setAttribute("lMenu1",lmenu1);
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
